<template>
  <div class="cs-page-container">
    <div class="cs-filter-container">
      <el-select
        v-model="listQuery.channel"
        clearable
        filterable
        placeholder="渠道"
      >
        <el-option
          v-for="(channel, i) in channels"
          :key="i"
          :label="channel"
          :value="channel"
        />
      </el-select>
      <el-date-picker
        v-model="daterangeValue"
        :picker-options="daterangePickerOptions"
        type="daterange"
        align="right"
        unlink-panels
        range-separator="至"
        start-placeholder="起始时间"
        end-placeholder="结束时间"
        value-format="yyyy-MM-dd"
        clearable
        @change="daterangeChangedTimestamp"
      />
      <el-button
        type="primary"
        icon="el-icon-search"
        :loading="listLoading"
        @click="handleFilter"
      >查询</el-button>
      <el-button
        type="info"
        size="small"
        icon="el-icon-refresh-right"
        @click="resetFilter"
      >重置</el-button>
    </div>
    <div class="cs-filter-result">
      <el-table
        v-loading="listLoading"
        :data="list"
        :height="'calc(100vh - 300px)'"
        border
        fit
        size="small"
        highlight-current-row
        element-loading-text="拼命加载中"
        element-loading-spinner="el-icon-loading"
      >
        <el-table-column
          align="center"
          label="日期"
        >
          <template slot-scope="{row}">
            <span>{{ row.targetDate | parseTime('{y}-{m}-{d}') }}</span>
          </template>
        </el-table-column>

        <el-table-column
          align="center"
          label="总充值"
          prop="totalRecharge"
        >
          <template slot-scope="{row}">
            <span>{{ row.totalRecharge / 100 }}</span>
          </template>
        </el-table-column>

        <el-table-column
          align="center"
          label="充值人数"
          prop="rechargeNumber"
        >
        </el-table-column>

        <el-table-column
          align="center"
          label="充值次数"
          prop="rechargeFrequency"
        >
        </el-table-column>

        <el-table-column
          align="center"
          label="充值页面充值次数/金额"
        >
          <template slot-scope="{row}">
            <span>{{ row.rechargePageFrequency }} / {{ row.rechargePageAmount / 100 }}</span>
          </template>
        </el-table-column>

        <el-table-column
          align="center"
          label="弹出页面充值次数/金额"
        >
          <template slot-scope="{row}">
            <span>{{ row.popupPageFrequency }} / {{ row.popupPageAmount / 100 }}</span>
          </template>
        </el-table-column>

        <el-table-column
          align="center"
          label="钻石不足充值次数/金额"
        >
          <template slot-scope="{row}">
            <span>{{ row.diamondFrequency }} / {{ row.diamondAmount / 100 }}</span>
          </template>
        </el-table-column>
        <el-table-column
          align="center"
          label="为了音视频充值次数/金额"
        >
          <template slot-scope="{row}">
            <span>{{ row.videoFrequency }} / {{ row.videoAmount / 100 }}</span>
          </template>
        </el-table-column>
        <el-table-column
          align="center"
          label="为了文字聊天充值次数/金额"
        >
          <template slot-scope="{row}">
            <span>{{ row.chatFrequency }} / {{ row.chatAmount / 100 }}</span>
          </template>
        </el-table-column>
        <el-table-column
          align="center"
          label="为了送礼充值次数/金额"
        >
          <template slot-scope="{row}">
            <span>{{ row.giftsFrequency }} / {{ row.giftsAmount / 100 }}</span>
          </template>
        </el-table-column>
        <el-table-column
          align="center"
          label="为了玩游戏充值次数/金额"
        >
          <template slot-scope="{row}">
            <span>{{ row.gamesFrequency }} / {{ row.gamesAmount / 100 }}</span>
          </template>
        </el-table-column>
      </el-table>
      <TablePagination
        :current-page="listQuery.page"
        :limit="listQuery.limit"
        :total="total"
        :loading="listLoading"
        @handleSizeChange="handleSizeChange"
        @handleCurrentChange="handleCurrentChangeOffset"
      />
    </div>
  </div>
</template>

<script>
  import TablePagination from '@/components/TablePagination/index'
  import DATEPICKER_OPTIONS from '@/config/datepickerOptions'
  import { xhrRechargeAnalysisList } from '@/api/analysis'
  // import { parseTime } from '@/utils'

  export default {
    name: 'RechargeAnalysis',
    components: { TablePagination },
    data() {
      return {
        list: [],
        channels: [],
        total: 0,
        listQuery: {
          offset: 0,
          limit: 100,
          startTime: null,
          endTime: null,
          channel: null
        },
        daterangeValue: '',
        daterangePickerOptions: DATEPICKER_OPTIONS.daterangePickerOptions
      }
    },
    created() {
      this.getChannels()
      this.doSearch()
    },
    methods: {
      getChannels() {
        this.xhrGetChannels().then(resp => {
          this.channels = resp.data
        })
      },
      doSearch() {
        xhrRechargeAnalysisList(this.listQuery).then(resp => {
          this.listLoading = false
          this.total = resp.data.count
          this.list = resp.data.list
        })
      }
    }
  }
</script>
